package mail

import (
	"gohub/pkg/config"
	"sync"
)

type From struct {
	Address string
	Name string
}

type Email struct {
	From From
	To []string
	Bcc []string
	Cc []string
	Subject string
	Text []byte
	HTML []byte
}

type Mailer struct {
	Driver Driver
}

// 单例
var once sync.Once

// 内部使用的 Mailer 对象
var internalMailer *Mailer

// 获取 Mailer (单例模式)实例
func NewMailer() *Mailer {
	once.Do(func() {
		internalMailer = &Mailer{
			Driver: &SMTP{},
		}
	})
	return internalMailer
}

func (mailer *Mailer) Send(email Email) bool {
	return mailer.Driver.Send(email, config.GetStringMapString("mail.smtp"))
}